home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Caml Light 0.7 / examples / kb / prelude.ml < prev    next >
Encoding:
Text File  |  1995-06-19  |  632 b   |  24 lines  |  [TEXT/MPS ]

  1. (**************** A few general-purpose functions *******************)
  2.  
  3. let fold f = fold_rec where rec fold_rec a1 = function
  4.     [] -> (a1,[])
  5.   | b1::bl ->
  6.       let (a2,c2) = f a1 b1 in
  7.       let (a,cl) = fold_rec a2 bl in
  8.         (a, c2::cl)
  9. ;;
  10.  
  11. let try_find f = try_find_rec where rec try_find_rec = function
  12.      []  -> failwith "try_find"
  13.   | a::l -> try f a with Failure _ -> try_find_rec l
  14. ;;
  15.  
  16. let partition p = part_rec where rec part_rec = function
  17.      []  -> [],[]
  18.   | a::l -> let (pos,neg) = part_rec l in
  19.               if p a then  a::pos, neg else pos, a::neg
  20. ;;
  21.  
  22. let message s = print_string s; print_newline()
  23. ;;
  24.